package com.haoqizhe.kernel.core.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Range;

import java.io.Serializable;

/**
 * @author haoqizhe.li
 * @date 2018/4/7 13:10
 */
@ApiModel("分页查询对象")
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageQuery<T> implements Serializable {

    @ApiModelProperty(value = "当前页码")
    @Range(min = 0,max = Integer.MAX_VALUE)
    private int pageNum = 1;

    @ApiModelProperty(value = "每页数量")
    @Range(min = 1,max = Integer.MAX_VALUE)
    private int pageSize = 10;

    @ApiModelProperty(value = "排序",notes = "例：create_time desc,update_time desc")
    private String orderBy;

    private T condition;

    public PageQuery(int pageNum, int pageSize) {
        super();
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }

    public int getOffset() {
        return (this.pageNum - 1) * this.pageSize;
    }

}
